<?php

namespace App\Http\Controllers;

header('Content-Type:text/html;charset=utf-8');

use http\Cookie;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class IndexController extends Controller
{
	public function index()
	{
		Redis::set('xxx','fdsfds');

		echo Redis::get('xxx');
	}
	
	
	
	
	
    public function indexss(Request $request)
    {

    	phpinfo();


        $path = $request->url();

		// 不附带查询串...
		$url = $request->url();

		var_dump($url);
		// 附带查询串...
		$url = $request->fullUrl();

		var_dump($url);


		//获取请求 Method
		$method = $request->method();
		echo "请求方法是：" . $method . "<br>";

		if ($request->isMethod('get')) {
			var_dump($method);
			echo "get";
		}

        echo '<pre>';
        var_dump($path);
        die;
    }

	public function setCookie()
	{
		$cookie = cookie('ceshi2','123456',3600);
		response('ss')->cookie($cookie);
	}

	public function getCookie()
	{
		echo request()->cookie('test');
	}

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Request $request)
    {
		$users = \DB::table('users')->pluck('id','name')->toArray();
		echo '<pre>';
		var_dump($users);
		die;


//		echo url()->current();
//		echo '<br>';

// Get the current URL including the query string...
//		echo url()->full();
//		echo '<br>';
// Get the full URL for the previous request...
//		echo url()->previous();

//		$this->setCookie();
    	 //设置cookie
//		$av =  response('ssss')->cookie('abc2','value',3600);
//
//		$cookie = $request->cookie('abc');
//		var_dump($cookie);
//
//
//        $param = $request->input('test');
//        var_dump($param);
//        $queryParam = $request->query('test');
//        var_dump($queryParam);
    }



	public function dikaer()
    {
		echo '笛卡尔积';

		$arr = [
			'7'=>[
				'白色',
				'黑色',
				'绿色',
			],
			'10'=>[
				'M',
				'L',
				'XL',
				'XXXL'
			],
			'12'=>[
				'纯棉',
				'聚氯乙烯',
				'丝绸',
			],
			'15'=>[
				'青年',
				'学生'
			]
		];

		$attr = [
			'7'=>[
				'2'=>'蓝色',
				'5'=>'白色'
			],
			'8'=>[
				'3'=>'X',
				'1'=>'L',
				'4'=>'XL'
			],
			'10'=>[
				'9'=>'纯棉',
				'11'=>'透气'
			],
			'14'=>[
				'22'=>'英伦',
				'23'=>'日韩',
				'24'=>'复古'
			]
		];

		$this->mydikaer($attr);
    }


	public function mydikaer($data)
    {
		//抛出要计算的数组的第一个数组
		$arr = array_shift($data);

		$i = 0;
		foreach ($data as $k => $item) {
			$res = [];
			if($i == 0){
				foreach ($arr as $k1 => $v1) {
					foreach ($item as $k2 => $v2) {
						$tmp = [];
						$tmp[$k1] = $v1;
						$tmp[$k2] = $v2;
						$res[] = $tmp;
					}
				}
				$arr = $res;
			}else{
				foreach ($arr as $k1 => $v1) {
					foreach ($item as $k2 => $v2) {
						$v1[$k2] = $v2;
						$res[] = $v1;
						array_pop($v1);
					}

				}
				$arr = $res;
			}
			$i++;
		}
		
		return $arr;
    }




	public function dikaerji($data)
    {
		$result = array();
		foreach (array_shift($data) as $k=>$item) {
			$result[] = array($k=>$item);
		}
		
		foreach ($data as $k => $v) {
			$result2 = [];
			foreach ($result as $k1=>$item1) {
				foreach ($v as $k2=>$item2) {
					$temp     = $item1;
					$temp[$k2]   = $item2;
					$result2[] = $temp;
				}
			}
			echo '<pre>';
			var_dump($result2);
			$result = $result2;
		}

		echo '<pre>';
		var_dump($result);
		die;
    }

	/**
	 ** 实现二维数组的笛卡尔积组合
	 ** $arr 要进行笛卡尔积的二维数组
	 ** $str 最终实现的笛卡尔积组合,可不写
	 ** @return array
	 **/
	function cartesian($arr,$str = array()){
		//去除第一个元素
		$first = array_shift($arr);
		//判断是否是第一次进行拼接
		if(count($str) > 1) {
			foreach ($str as $k => $val) {
				foreach ($first as $key => $value) {
					//最终实现的格式 1,3,76
					//可根据具体需求进行变更
					$str2[] = $val.','.$value;
				}
			}
		}else{
			foreach ($first as $key => $value) {
				//最终实现的格式 1,3,76
				//可根据具体需求进行变更
				$str2[] = $value;
			}
		}

		//递归进行拼接
		if(count($arr) > 0){
			$str2 = $this->cartesian($arr,$str2);
		}
		//返回最终笛卡尔积
		echo '<pre>';
		var_dump($str2);
		die;
	}
}
